Release 10.1A: OpenEdge Development:
Progress 4GL Handbook
Manipulating the objects in a window
In this section, you’ll learn how to locate and identify the objects in a window by their handles. Because both static and dynamic objects have handles, and attributes and methods you can manipulate through those handles, this material applies to both static and dynamic objects. Later in this chapter, you’ll add new dynamic objects to the sample window.
As discussed in the Chapter 14, "Defining Functions and Building Super Procedures," one of the principal reasons why you might need to locate and manipulate objects by their handles is to write generic code to adjust the appearance or behavior of objects from another procedure, such as a super procedure. The sample super procedure
h-WinSuper.pshowed a very simple example of that.Next, you’ll write another super procedure to make some more substantial adjustments to the objects in the test window by “walking the widget tree” of the window.
![]()
To write another super procedure:
- Open the version of
h-CustOrderWin1.wfrom Chapter Four as a starting point, as you’ve done before and save it ash-CustOrderWin7.w.- In the main block of
h-CustOrderWin7.w, add two lines of code, one to useh-StartSuper.pto start or locate a new super procedure calledh-dynsuper.pand the second to run an internal procedure that Progress locates inh-dynsuper.p:
- Create a new structured procedure in the AppBuilder.
- Create a new internal procedure called changeFields.
- Define these variables that the procedure needs:
These handles allow you to identify the procedure’s current window, its frame, each field or other object inside the frame, and finally the columns of the order browse in the frame. To understand how to walk down through the frame to locate objects, you need to look at the hierarchy of the objects the handles point to.
First, look at how a procedure’s window handles are established. Progress defines a single default window for a session, and uses this window to display objects in when no other window is specified. There is a built-in system handle, called
DEFAULT-WINDOW, that holds the handle of this window. There is also a system handle, calledCURRENT-WINDOW, that Progress uses as the default for parenting frames, dialog boxes, and messages. Initially, theCURRENT-WINDOWis the same as theDEFAULT-WINDOW.There is no
DEFINE WINDOWstatement in Progress. All other windows in a session are dynamic windows that you create with theCREATE WINDOWstatement. When you start a procedure, you can set theCURRENT-WINDOWsystem handle to be a window created by your procedure. There is also aCURRENT-WINDOWattribute for theTHIS-PROCEDUREsystem handle, which holds the procedure handle of the procedure containing the reference toTHIS-PROCEDURE. Setting theCURRENT-WINDOWattribute sets the default parenting for all frames, dialog boxes, and messages used in that procedure without affecting windows defined by other procedures.The standard code the AppBuilder uses for a window includes statements to set the
CURRENT-WINDOWsystem handle to the dynamic window the AppBuilder code creates, as you saw in Chapter 5, " Examining the Code the AppBuilder Generates." It also sets theCURRENT-WINDOWattribute ofTHIS-PROCEDUREto the same window:
Other procedures can access the window of a procedure that adheres to this convention by referencing its
CURRENT-WINDOWattribute. Therefore, the first thing thechangeFieldsprocedure does is obtain that window handle. Because it is a super procedure ofh-CustOrderWin7.w, theTARGET-PROCEDUREsystem handle withinh-dynsuper.phas the same value asTHIS-PROCEDUREdoes withinh-CustOrderWin7.w:
If the
h-CustOrderWin7.wprocedure did not set itsCURRENT-WINDOWattribute, you would need to use some other mechanism to identify it. Because this is the most straightforward way to associate a window with a procedure, you should adopt this convention, whether you use this standard AppBuilder template or not.A procedure can create more than one window. Only one window can be the procedure’s
CURRENT-WINDOW. If your procedures use more than one window, then you need to use some other convention to locate other windows in the procedure. For example, you could store a character string representing a list of other window handles in the window’sPRIVATE-DATAattribute. The standard for procedures you build in the AppBuilder, as well as in the SmartObjects that are the components you can build applications from, is to create only one window in a procedure.The next level down from a window is the frame or frames that are parented to the window. To identify the first frame in a window, you use its
FIRST-CHILDattribute:
If a window has more than one frame, you can access the other frames by following the
NEXT-SIBLINGof the first frame, which chains the frames together.As you might expect, you go down to the objects in a frame by accessing its
FIRST-CHILDattribute. But there is another level of object in between the frame and the fields and other objects in the frame. This level is called a field group.Remember that Progress supports the notion of a
DOWNframe, which displays multiple instances of the same fields to show multiple records from a result set in a manner similar to what a browse does. This visualization is used primarily by older character-mode applications where there is no browse. For this reason most graphical applications use only one-down frames. Regardless of this, the notion of this iteration through multiple instances of the same fields is still present in all frames, and each instance of the fields in the frame is a field group. Therefore, when you reference theFIRST-CHILDattribute of a frame, you are accessing its first field group:
Unless your frame has a
DOWNattribute greater than one, the field group is not very interesting in itself. If the frame has more than one field group, you can use theNEXT-SIBLINGchain to get at each of them. Otherwise, you just proceed down another level to get to the first object in the frame:
In
changeFields, you can combine all these steps into a singleASSIGNstatement:
The
ASSIGNstatement is more efficient than a sequence of individual assignments. The steps in the sequence are executed in order, just as they appear. For instance, the value of thehObjectvariable assigned in the third step (to the field group) can then be used in the fourth step to assign the same variable a new value equal to the first object in the group.Figure 18–11 is a pictorial representation of how these different objects and their handles are related.
Figure 18–11: Relationships between objects in a window
![]()
|
Copyright © 2005 Progress Software Corporation www.progress.com Voice: (781) 280-4000 Fax: (781) 280-4095 |